package com.lgq.demo.blog;

import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;
import com.lgq.demo.common.model.Blog;

/**
 * BlogValidator.
 */
public class BlogValidator extends Validator {
	
	protected void validate(Controller controller) {
        // 属性域，页面输出的错误key，页面输出的错误信息
		validateRequiredString("blog.title", "titleMsg", "请输入Blog标题!");
		validateRequiredString("blog.content", "contentMsg", "请输入Blog内容!");
	}


    /**
     * 验证发生错误的时候才执行
     * @param controller
     */
	protected void handleError(Controller controller) {
		controller.keepModel(Blog.class);
		
		String actionKey = getActionKey();
		if (actionKey.equals("/blog/save")) {
            controller.render("add.html");
        } else if (actionKey.equals("/blog/update")) {
            controller.render("edit.html");
        }
	}
}
